//package topcoderme;

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;


public class WickedTeacher
{
        int[] strlen;
        int tot;
        int[] p10 = new int[52];
        int[] vi;
        long[][] dp;
        public long dfs(int msk, int rem, int K){
            if( Integer.bitCount(msk)==tot ){
                return rem==0 ? 1 : 0 ;
            }
            if( dp[msk][rem]>=0 ){
                return dp[msk][rem];
            }
            dp[msk][rem]=0;

            for(int i=0;i<tot;++i){
                if( ( msk&(1<<i) )==0 ){
                    int nrem = (rem*p10[ strlen[i] ] + vi[i] )  ;
                    dp[msk][rem]+= dfs(msk|(1<<i), nrem%K, K);
                }
            }

            return dp[msk][rem];
        }
	public String cheatProbability(String[] numbers, int K)
	{
           
            tot = numbers.length;
            p10[1]=10%K;
            for(int i=2;i<=50;++i){
                p10[i] = (p10[i-1]*10 ) %K;
            }
            vi = new int[ tot ];
            strlen = new int [tot];
            for(int i=0;i<tot;++i){
                vi[i] = new BigInteger(numbers[i]).mod(new BigInteger(""+K) ).intValue();
                strlen[i] = numbers[i].length();
            }
            dp = new long[1<<tot][K+1];
            for(int i=0,j=dp.length; i<j;++i ){
                Arrays.fill(dp[i], -1);
            }
            long var = dfs(0,0,K);
            long denom=1;
            for(int i=1;i<=tot;++i)denom*=i;
            long gcd = GCD(var,denom);

            return ""+var/gcd+"/"+denom/gcd;
        }
        public long GCD(long p, long q){
            while( p>0 ){
                long t = q%p;
                q = p;
                p = t;
            }
            return q;
        }


}
//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
